﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Transport
{
    public class DichVuControl
    {
        transportEntities db;

        public DichVuControl()
        {
            db = new transportEntities();
        }

        public List<dich_vu> listAll()
        {
            try
            {
                return db.dich_vu.ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }
        public dich_vu findByID(string Id)
        {
            try
            {
                return db.dich_vu.SingleOrDefault(t => t.id_dich_vu == Id);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public dich_vu findByName(string Name)
        {
            try
            {
                return db.dich_vu.SingleOrDefault(t => t.ten_dich_vu == Name);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public string getServiceId(string Name)
        {
            try
            {
                return db.dich_vu.SingleOrDefault(t => t.ten_dich_vu == Name).id_dich_vu;
            }
            catch (Exception)
            {
                return "";
            }
        }

        public bool insert(dich_vu value)
        {
            try
            {
                db.dich_vu.AddObject(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool update(dich_vu value)
        {
            try
            {
                dich_vu st = db.dich_vu.SingleOrDefault(t => t.id_dich_vu == value.id_dich_vu);
                st = value;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool delete(string Id)
        {
            try
            {
                dich_vu st = db.dich_vu.SingleOrDefault(t => t.id_dich_vu == Id);
                db.dich_vu.DeleteObject(st);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}